package cn.funeralobjects.upms.controller;

import cn.funeralobjects.common.service.CommonCloudCrudService;
import cn.funeralobjects.common.web.controller.CommonCloudCrudController;
import cn.funeralobjects.common.web.controller.converter.ModelMapper;
import cn.funeralobjects.upm.web.model.MCustomPath;
import cn.funeralobjects.upm.web.model.VCustomPath;
import cn.funeralobjects.upms.api.CustomPathApi;
import cn.funeralobjects.upms.controller.converter.CustomPathMapper;
import cn.funeralobjects.upms.entity.ECustomPath;
import cn.funeralobjects.upms.model.CustomPath;
import cn.funeralobjects.upms.service.CustomPathService;
import cn.funeralobjects.util.ReactorUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * @author FuneralObjects
 * Create date: 2020/5/27 6:58 PM
 */
@RestController
@RequestMapping("/custom-path")
public class CustomPathController implements CustomPathApi, CommonCloudCrudController<VCustomPath, MCustomPath, CustomPath, ECustomPath, Integer> {

    @Resource
    private CustomPathService customPathService;
    @Resource
    private CustomPathMapper customPathMapper;

    @Override
    public CommonCloudCrudService<CustomPath, ECustomPath, Integer> commonCloudCrudService() {
        return customPathService;
    }

    @Override
    public ModelMapper<MCustomPath, CustomPath, ECustomPath, VCustomPath> modelMapper() {
        return customPathMapper;
    }


    @DeleteMapping("/{id}/relation-role-{roleId}")
    @Override
    public Mono<Void> removeRoleFromCustomPath(@PathVariable Integer id, @PathVariable Integer roleId) {
        return Mono.just(id).flatMap(ReactorUtils.thenEmpty(i -> customPathService.removeRoleFromCustomPath(roleId, i)));
    }
}
